﻿namespace OP10.ViewModels
{
    public class ST03CyManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST03CyManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;

            InitParam();
        }

        private void InitParam()
        {
            //气缸感应器延时参数初始化赋值
            CylinderDelay.DelayTime01 = ST03DownPushCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime02 = ST03JackMaterialCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime03 = ST03DownPushCy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime04 = ST03JackMaterialCy.cylinderPCToPLC_Global.tGoTime;


            checkModel.IsQGOriginCheck01 = ST03DownPushCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck02 = ST03JackMaterialCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck03 = ST03DownPushCy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck04 = ST03JackMaterialCy.cylinderPCToPLC_Global.bOrgSenByPass;

            checkModel.IsQGWorkCheck01 = ST03DownPushCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck02 = ST03JackMaterialCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck03 = ST03DownPushCy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck04 = ST03JackMaterialCy.cylinderPCToPLC_Global.bWorkSenByPass;
        }
        #region 事件


        private DelegateCommand _GoBackCommand;
        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));
        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST03");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST03View, param);
        }
        /// <summary>
        /// 气缸屏蔽
        /// </summary>
        private DelegateCommand<string> _CylinderPinBiCommand;
        public DelegateCommand<string> CylinderPinBiCommand =>
            _CylinderPinBiCommand ?? (_CylinderPinBiCommand = new DelegateCommand<string>(ExecuteCylinderPinBiCommand));
        void ExecuteCylinderPinBiCommand(string p)
        {
            switch (p)
            {
                case "ST3下压气缸原点":
                    ST03DownPushCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST3顶料气缸原点":
                    ST03JackMaterialCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST3下压气缸动点":
                    ST03DownPushCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST3顶料气缸动点":
                    ST03JackMaterialCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                default:
                    break;
            }
        }
        /// <summary>
        /// 气缸解除屏蔽
        /// </summary>
        private DelegateCommand<string> _CylinderUnPinBiCommand;
        public DelegateCommand<string> CylinderUnPinBiCommand =>
            _CylinderUnPinBiCommand ?? (_CylinderUnPinBiCommand = new DelegateCommand<string>(ExecuteCylinderUnPinBiCommand));
        void ExecuteCylinderUnPinBiCommand(string p)
        {
            switch (p)
            {
                case "ST3下压气缸原点":
                    ST03DownPushCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST3顶料气缸原点":
                    ST03JackMaterialCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST3下压气缸动点":
                    ST03DownPushCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST3顶料气缸动点":
                    ST03JackMaterialCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                default:
                    break;
            }
        }
        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));
        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {
                case "DelayTime01":
                    ST03DownPushCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime01;
                    break;
                case "DelayTime02":
                    ST03JackMaterialCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime02;
                    break;
                case "DelayTime03":
                    ST03DownPushCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime03;
                    break;
                case "DelayTime04":
                    ST03JackMaterialCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime04;
                    break;
                default:
                    break;
            }
        }
        #endregion
        #region 属性  

        private CylinderDelayModel _cylinderDelay;
        public CylinderDelayModel CylinderDelay
        {
            get { return _cylinderDelay ?? (_cylinderDelay = new CylinderDelayModel()); }
            set { SetProperty(ref _cylinderDelay, value); }
        }
        private CylinderSensorCheckModel _checkModel;
        public CylinderSensorCheckModel checkModel
        {
            get { return _checkModel ?? (_checkModel = new CylinderSensorCheckModel()); }
            set { SetProperty(ref _checkModel, value); }
        }
        #endregion
    }
}
